/*
 * Created on Feb 10, 2005
 * Created by dfhuynh
 */
package edu.mit.simile.longwell.query.bucket;

import java.util.Comparator;

/**
 * @author dfhuynh
 */
public class Bucket {
	final public String	m_bucketerName;
	 public String m_label;
	final public String m_bucketerParameter;
	final public int	m_count;

	public Bucket(
		String 	bucketerName,
		String	bucketerParameter,
		String 	label,
		int		count
	) {
		m_bucketerName = bucketerName; 
		m_bucketerParameter = bucketerParameter;
		m_label = label;
		m_count = count;
	}
	
	public String getLabel() {
		return m_label;
	}
	
	public String getLabelCustom(){
		if(m_label.startsWith("\"") && m_label.endsWith("\"")){
			String tmp = m_label.substring(1, m_label.length()-1);
			if(tmp.contains("\"")){
				tmp = tmp.replace("\"", "");
				m_label="\""+tmp+"\"";
			}
			
		}
		/*
		if(m_label.contains(" ")){
			m_label = m_label.replace(" ", "_");
		}		
		if(m_label.contains("'")){
			m_label = m_label.replace("'", "_");
		}
		if(m_label.contains("�")){
			m_label = m_label.replace("�", "");
		}
		*/
		return m_label;
	}
	
	public String addQuotes(String str){
		str= str.replace("\"", "");
		return "\""+str+"\""; 
	}
	
	public String getBucketerName() {
		return m_bucketerName;
	}
	
	public int getCount() {
		return m_count;
	}
	
	public String getBucketerParameter() {
		return m_bucketerParameter;
	}

	static class BucketComparator implements Comparator {
		/* (non-Javadoc)
		 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
		 */
		public int compare(Object o1, Object o2) {
			Bucket b1 = (Bucket) o1;
			Bucket b2 = (Bucket) o2;

			int i = b1.m_label.compareToIgnoreCase(b2.m_label);
			if (i == 0) {
				i = b1.m_bucketerName.compareTo(b2.m_bucketerName);
			}
			return i;
		}
		
	}
}
